/**
 * Created by meiyun1 on 2017/8/9.
 */
import IScroll from 'iscroll'

export default {
  heightEqWidth: {
    update (el, binding) {
      if (binding.value === 'second') {
        const width = el.scrollWidth
        const height = width - 20
        el.style.height = `${height}px`
      }
    }
  },
  iscroll: {
    inserted (el) {
      const scroll = new IScroll(el, {
        scrollbars: false,
        mouseWheel: true
        // fadeScrollbars: true,
      })
      el.isscroll = scroll
    },
    update (el, binding) {
      if (!el.isscroll) {
        const scroll = new IScroll(el, {
          scrollbars: false,
          mouseWheel: true
          // fadeScrollbars: true,
        })
        el.isscroll = scroll
      } else {
        const t = setTimeout(() => {
          el.isscroll.refresh()
          clearTimeout(t)
        }, 300)
      }
    }
  }
}
